<?php
namespace Usuarios\Model;

use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;

class Usuario implements InputFilterAwareInterface {

   public $id;
   public $id_profesor;
   public $matricula;
   public $id_funcionario;
   public $username;
   public $password;
   public $nombre;
   public $apellido;
   public $sexo;
   public $domicilio;
   public $mail;
   public $telefono;
   public $estado_civil;
   public $fecha_nacimiento;
   public $lugar_nacimiento;
   public $nacionalidad;
   protected $inputFilter;

   public function exchangeArray($data) {
      $this->id               = (isset($data['id'])) ? $data['id'] : null;
      $this->id_profesor      = (isset($data['id_profesor'])) ? $data['id_profesor'] : null;
      $this->matricula        = (isset($data['matricula'])) ? $data['matricula'] : null;
      $this->id_funcionario   = (isset($data['id_funcionario'])) ? $data['id_funcionario'] : null;
      $this->username         = (isset($data['username'])) ? $data['username'] : null;
      $this->password         = (isset($data['password'])) ? md5($data['password']) : null;
      $this->nombre           = (isset($data['nombre'])) ? $data['nombre'] : null;
      $this->apellido         = (isset($data['apellido'])) ? $data['apellido'] : null;
      $this->sexo             = (isset($data['sexo'])) ? $data['sexo'] : null;
      $this->domicilio        = (isset($data['domicilio'])) ? $data['domicilio'] : null;
      $this->mail             = (isset($data['mail'])) ? $data['mail'] : null;
      $this->telefono         = (isset($data['telefono'])) ? $data['telefono'] : null;
      $this->estado_civil     = (isset($data['estado_civil'])) ? $data['estado_civil'] : null;
      $this->fecha_nacimiento = (isset($data['fecha_nacimiento'])) ? $data['fecha_nacimiento'] : null;
      $this->lugar_nacimiento = (isset($data['lugar_nacimiento'])) ? $data['lugar_nacimiento'] : null;
      $this->nacionalidad     = (isset($data['nacionalidad'])) ? $data['nacionalidad'] : null;
   }

   public function getArrayCopy() {
      return get_object_vars($this);
   }

   public function setMatricula($mat) {
      $this->matricula = $mat;
   }

   public function setIdProfesor($id) {
      $this->id_profesor = $id;
   }

   public function setIdFuncionario($id) {
      $this->id_funcionario = $id;
   }


   public function setInputFilter(InputFilterInterface $inputFilter) {
      throw new \Exception("Not used");
   }

   public function getInputFilter() {
      if (!$this->inputFilter) {
         $inputFilter = new InputFilter();
         $factory     = new InputFactory();

         $inputFilter->add($factory->createInput(array(
            'name'     => 'id',
            'required' => true,
            'filters'  => array(
               array('name' => 'Int'),
            ),
         )));

         $inputFilter->add($factory->createInput(array(
            'name'     => 'id_profesor',
            'required' => true,
            'filters'  => array(
               array('name' => 'Int'),
            ),
         )));

         $inputFilter->add($factory->createInput(array(
            'name'     => 'matricula',
            'required' => true,
            'filters'  => array(
               array('name' => 'Int'),
            ),
         )));

         $inputFilter->add($factory->createInput(array(
            'name'     => 'id_funcionario',
            'required' => true,
            'filters'  => array(
               array('name' => 'Int'),
            ),
         )));

         $inputFilter->add($factory->createInput(array(
            'name'     => 'username',
            'required' => true,
            'filters'  => array(
               array('name' => 'StripTags'),
               array('name' => 'StringTrim'),
            ),
            'validators' => array(
               array(
                  'name' => 'StringLength',
                  'options' => array(
                     'encoding' => 'UTF-8',
                     'min' => 1,
                     'max' => 20,
                  ),
               ),
            ),
         )));

         $inputFilter->add($factory->createInput(array(
            'name'     => 'password',
            'required' => true,
            'filters'  => array(
               array('name' => 'StripTags'),
               array('name' => 'StringTrim'),
            ),
            'validators' => array(
               array(
                  'name' => 'StringLength',
                  'options' => array(
                     'encoding' => 'UTF-8',
                     'min' => 4,
                     'max' => 32,
                  ),
               ),
            ),
         )));

         $inputFilter->add($factory->createInput(array(
            'name'     => 'password_confirm',
            'required' => true,
            'filters'  => array(
               array('name' => 'StripTags'),
               array('name' => 'StringTrim'),
            ),
            'validators' => array(
               array(
                  'name' => 'StringLength',
                  'options' => array(
                     'encoding' => 'UTF-8',
                     'min' => 4,
                     'max' => 32,
                  ),
               ),
            ),
         )));

         $inputFilter->add($factory->createInput(array(
            'name'     => 'nombre',
            'required' => true,
            'filters'  => array(
               array('name' => 'StripTags'),
               array('name' => 'StringTrim'),
            ),
            'validators' => array(
               array(
                  'name' => 'StringLength',
                  'options' => array(
                     'encoding' => 'UTF-8',
                     'min' => 2,
                     'max' => 30,
                  ),
               ),
            ),
         )));

         $inputFilter->add($factory->createInput(array(
            'name'     => 'apellido',
            'required' => true,
            'filters'  => array(
               array('name' => 'StripTags'),
               array('name' => 'StringTrim'),
            ),
            'validators' => array(
               array(
                  'name' => 'StringLength',
                  'options' => array(
                     'encoding' => 'UTF-8',
                     'min' => 2,
                     'max' => 30,
                  ),
               ),
            ),
         )));

         $inputFilter->add($factory->createInput(array(
            'name'     => 'sexo',
            'required' => true,
            'filters'  => array(
               array('name' => 'StripTags'),
               array('name' => 'StringTrim'),
            ),
            'validators' => array(
               array(
                  'name' => 'StringLength',
                  'options' => array(
                     'encoding' => 'UTF-8',
                     'min' => 1,
                     'max' => 50,
                  ),
               ),
            ),
         )));

         $inputFilter->add($factory->createInput(array(
            'name'     => 'domicilio',
            'required' => true,
            'filters'  => array(
               array('name' => 'StripTags'),
               array('name' => 'StringTrim'),
            ),
            'validators' => array(
               array(
                  'name' => 'StringLength',
                  'options' => array(
                     'encoding' => 'UTF-8',
                     'min' => 1,
                     'max' => 50,
                  ),
               ),
            ),
         )));

         $inputFilter->add($factory->createInput(array(
            'name'     => 'mail',
            'required' => true,
            'filters'  => array(
               array('name' => 'StripTags'),
               array('name' => 'StringTrim'),
            ),
            'validators' => array(
               array(
                  'name' => 'StringLength',
                  'options' => array(
                     'encoding' => 'UTF-8',
                     'min' => 1,
                     'max' => 50,
                  ),
               ),
            ),
         )));

         $inputFilter->add($factory->createInput(array(
            'name'     => 'telefono',
            'required' => true,
            'filters'  => array(
               array('name' => 'StripTags'),
               array('name' => 'StringTrim'),
            ),
            'validators' => array(
               array(
                  'name' => 'StringLength',
                  'options' => array(
                     'encoding' => 'UTF-8',
                     'min' => 1,
                     'max' => 16,
                  ),
               ),
            ),
         )));

         $inputFilter->add($factory->createInput(array(
            'name'     => 'estado_civil',
            'required' => true,
            'filters'  => array(
               array('name' => 'StripTags'),
               array('name' => 'StringTrim'),
            ),
            'validators' => array(
               array(
                  'name' => 'StringLength',
                  'options' => array(
                     'encoding' => 'UTF-8',
                     'min' => 1,
                     'max' => 10,
                  ),
               ),
            ),
         )));

         $inputFilter->add($factory->createInput(array(
            'name'     => 'fecha_nacimiento',
            'required' => true,
            'filters'  => array(
               array('name' => 'StripTags'),
               array('name' => 'StringTrim'),
            ),
            'validators' => array(
               array(
                  'name' => 'StringLength',
                  'options' => array(
                     'encoding' => 'UTF-8',
                     'min' => 4,
                     'max' => 24,
                  ),
               ),
            ),
         )));

         $inputFilter->add($factory->createInput(array(
            'name'     => 'lugar_nacimiento',
            'required' => true,
            'filters'  => array(
               array('name' => 'StripTags'),
               array('name' => 'StringTrim'),
            ),
            'validators' => array(
               array(
                  'name' => 'StringLength',
                  'options' => array(
                     'encoding' => 'UTF-8',
                     'min' => 1,
                     'max' => 40,
                  ),
               ),
            ),
         )));

         $inputFilter->add($factory->createInput(array(
            'name'     => 'fecha_nacimiento',
            'required' => true,
            'filters'  => array(
               array('name' => 'StripTags'),
               array('name' => 'StringTrim'),
            ),
            'validators' => array(
               array(
                  'name' => 'StringLength',
                  'options' => array(
                     'encoding' => 'UTF-8',
                     'min' => 1,
                     'max' => 24,
                  ),
               ),
            ),
         )));

         $inputFilter->add($factory->createInput(array(
            'name'     => 'nacionalidad',
            'required' => true,
            'filters'  => array(
               array('name' => 'StripTags'),
               array('name' => 'StringTrim'),
            ),
            'validators' => array(
               array(
                  'name' => 'StringLength',
                  'options' => array(
                     'encoding' => 'UTF-8',
                     'min' => 1,
                     'max' => 24,
                  ),
               ),
            ),
         )));

         $this->inputFilter = $inputFilter;
      }

      return $this->inputFilter;
   }
}
